package com.campus.mapper;

import com.campus.domain.entity.LostItem;
import com.campus.domain.dto.LostItemQueryDTO;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 失物Mapper
 */
@Mapper
public interface LostItemMapper {
    
    // 插入失物
    @Insert("INSERT INTO lost_items(user_id, title, description, location, found_time, category, status, view_count, like_count, comment_count) " +
            "VALUES(#{userId}, #{title}, #{description}, #{location}, #{foundTime}, #{category}, 0, 0, 0, 0)")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(LostItem lostItem);
    
    // 根据ID查询
    @Select("SELECT * FROM lost_items WHERE id = #{id} AND is_deleted = 0")
    LostItem selectById(Long id);
    
    // 查询列表（使用XML）
    List<LostItem> selectList(LostItemQueryDTO queryDTO);
    
    // 查询总数（使用XML）
    Long selectCount(LostItemQueryDTO queryDTO);
    
    // 更新失物
    @Update("UPDATE lost_items SET title = #{title}, description = #{description}, " +
            "location = #{location}, found_time = #{foundTime}, category = #{category} " +
            "WHERE id = #{id}")
    int update(LostItem lostItem);
    
    // 删除失物（逻辑删除）
    @Update("UPDATE lost_items SET is_deleted = 1 WHERE id = #{id}")
    int deleteById(Long id);
    
    // 增加浏览数
    @Update("UPDATE lost_items SET view_count = view_count + 1 WHERE id = #{id}")
    int incrementViewCount(Long id);
    
    // 增加点赞数
    @Update("UPDATE lost_items SET like_count = like_count + 1 WHERE id = #{id}")
    int incrementLikeCount(Long id);
    
    // 减少点赞数
    @Update("UPDATE lost_items SET like_count = like_count - 1 WHERE id = #{id}")
    int decrementLikeCount(Long id);
    
    // 增加评论数
    @Update("UPDATE lost_items SET comment_count = comment_count + 1 WHERE id = #{id}")
    int incrementCommentCount(Long id);
    
    // 更新状态
    @Update("UPDATE lost_items SET status = #{status} WHERE id = #{id}")
    int updateStatus(@Param("id") Long id, @Param("status") Integer status);
}

